﻿#include "lvgl_backlight_anim.h"

#if 1
#define lvgl_backlight_anim_debug(format, ...) lvgl_project_debug("[lvgl power off anim]-",format,##__VA_ARGS__);
#else
#define lvgl_backlight_anim_debug(format, ...) ;
#endif


//----进出----//
void lvgl_backlight_anim_in_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_backlight_anim_in_ready_cb(lv_anim_t* anim)
{

    lvgl_backlight_anim_debug("---------anim in ready---------");

    lv_anim_del(&lvgl_backlight_data.anim_in,NULL);

    lv_obj_set_pos(lvgl_backlight_data.cont_main, lvgl_backlight_data.main_cont_x, lvgl_backlight_data.main_cont_y);

    lvgl_group_save_focus_obj();

    lvgl_group_add_obj(&lvgl_backlight_data.cont_main);
    lvgl_group_focus_obj(&lvgl_backlight_data.cont_main);

}

void lvgl_backlight_anim_in_start(int mode, int time)
{
#if LVGL_ANIM_SWITCH

    lvgl_backlight_anim_debug("---------anim in start---------");

    lv_anim_path_init(&lvgl_backlight_data.anim_path_in);
    lv_anim_path_set_cb(&lvgl_backlight_data.anim_path_in, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_backlight_data.anim_in);


    lv_anim_set_exec_cb(&lvgl_backlight_data.anim_in, lvgl_backlight_anim_in_cb);
    lv_anim_set_ready_cb(&lvgl_backlight_data.anim_in, lvgl_backlight_anim_in_ready_cb);
    lv_anim_set_values(&lvgl_backlight_data.anim_in, lv_obj_get_y(lvgl_backlight_data.cont_main),lvgl_backlight_data.main_cont_y);
    lv_anim_set_time(&lvgl_backlight_data.anim_in, 300);
    lv_anim_set_var(&lvgl_backlight_data.anim_in, lvgl_backlight_data.cont_main);

    lv_anim_set_path(&lvgl_backlight_data.anim_in, &lvgl_backlight_data.anim_path_in);
    lv_anim_start(&lvgl_backlight_data.anim_in);

#else


    lvgl_backlight_anim_in_ready_cb(NULL);

#endif




}


void lvgl_backlight_anim_out_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}
void lvgl_backlight_anim_out_ready_cb(lv_anim_t* anim)
{

    lvgl_backlight_anim_debug("---------anim out ready---------");

    lv_anim_del(&lvgl_backlight_data.anim_out,NULL);
    lvgl_backlight_close();

}

void lvgl_backlight_anim_out_start(int mode, int time)
{

    lvgl_group_remove_obj(&lvgl_backlight_data.cont_main);

#if LVGL_ANIM_SWITCH

    lvgl_backlight_anim_debug("---------anim out start---------");

    lv_anim_path_init(&lvgl_backlight_data.anim_path_out);
    lv_anim_path_set_cb(&lvgl_backlight_data.anim_path_out, lv_anim_path_ease_in);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_backlight_data.anim_out);


    lv_anim_set_exec_cb(&lvgl_backlight_data.anim_out, lvgl_backlight_anim_out_cb);
    lv_anim_set_ready_cb(&lvgl_backlight_data.anim_out, lvgl_backlight_anim_out_ready_cb);
    lv_anim_set_values(&lvgl_backlight_data.anim_out, lv_obj_get_y(lvgl_backlight_data.cont_main), lv_obj_get_height(lv_scr_act()));
    lv_anim_set_time(&lvgl_backlight_data.anim_out, time);
    lv_anim_set_var(&lvgl_backlight_data.anim_out, lvgl_backlight_data.cont_main);

    lv_anim_set_path(&lvgl_backlight_data.anim_out, &lvgl_backlight_data.anim_path_out);
    lv_anim_start(&lvgl_backlight_data.anim_out);

#else


    lvgl_backlight_anim_out_ready_cb(NULL);

#endif

}
//----进出----//


